package it.unicam.cs.cosy.bioshape.gui;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URI;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;

/**
 * About Frame.
 * 
 * @author Buti Federico, Callisto De Donato Massimo
 */
public class About extends JDialog {

	private static final long serialVersionUID = 1L;
	private JLabel label1;
	private JLabel label2;
	private JLabel label5;
	private JPanel panel;
	private JPanel south;

	/**
	 * Creates the about frame.
	 * 
	 * @param owner
	 *            Application {@code Frame} controlling the window.
	 */
	public About(Frame owner) {
		super(owner);
		initComponents();
		setResizable(false);
		setModal(true);
		label5.addMouseListener(new MouseAdapter() {

			@Override
			public void mouseClicked(MouseEvent e) {
				try {
					if (Desktop.isDesktopSupported())
						Desktop.getDesktop().browse(
								new URI("http://cosy.cs.unicam.it/fase/"));
					else {
						System.err.println("Unable to Launch Default "
								+ "Browser: API not Supported...");
						System.err.println("JAVA SE 6 Desktop "
								+ "API non Supported!!");
						JOptionPane.showMessageDialog(null, "Unable to Launch "
								+ "Default Browser.", "API not Supported",
								JOptionPane.WARNING_MESSAGE);
					}
				} catch (Exception IOException) {
					System.err.println("Unable to Launch Default Browser: "
							+ "IO error...");
					JOptionPane.showMessageDialog(null,
							"Unable to Launch Default Browser.",
							"IO error occurred", JOptionPane.ERROR_MESSAGE);
				}
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			}

			@Override
			public void mouseExited(MouseEvent e) {
				setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
			}
		});
		//
		pack();
		setLocationRelativeTo(getOwner());
	}

	private void initComponents() {
		label1 = new JLabel();
		label2 = new JLabel();
		label5 = new JLabel();
		panel = new JPanel();
		panel.setBorder(new EmptyBorder(10, 10, 0, 10));
		panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
		south = new JPanel();
		south.setLayout(new FlowLayout(FlowLayout.CENTER));

		setTitle("About");
		setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		setIconImage(new ImageIcon("images/icon.png").getImage());
		{
			label1.setText("BioShape GUI 0.9a");
			label1.setHorizontalAlignment(SwingConstants.CENTER);
			label1.setFont(new Font("Tahoma", Font.BOLD, 23));
			label1.setAlignmentX(Component.CENTER_ALIGNMENT);
			panel.add(label1);

			label2.setText("Modelling and simulation environment for simulating biological processes");
			label2.setHorizontalAlignment(SwingConstants.CENTER);
			label2.setFont(new Font("Tahoma", Font.ROMAN_BASELINE, 12));
			label2.setAlignmentX(Component.CENTER_ALIGNMENT);
			panel.add(label2);

			JLabel label6 = new JLabel();
			label6.setIcon(new ImageIcon(Monitor.class
					.getResource("images/line.png")));
			label6.setAlignmentX(Component.CENTER_ALIGNMENT);
			panel.add(label6);
			JLabel credits = new JLabel("<html>"
					+ "<i>Project Leaders:</i> <br>"
					+ "<ul><li>Prof. Flavio Corradini </li>"
					+ "<li>Prof. Emanuela Merelli </li></ul>"
					+ "<i>Project Coordinator:</i> <br>"
					+ "<ul><li>Prof. Luca Tesei </li></ul>"
					+ "<i>Developers:</i> <br>"
					+ "<ul><li>Federico Buti (Phd Stud.) </li> "
					+ "<li>Gaston Alanis (Grad. Stud.) </li>"
					+ "<li>Matteo Micheletti (Grad. Stud.) </li>"
					+ "<li>Carmine Oliva (Grad. Stud.) </li>"
					+ "<li>Andrea Piermarteri (Grad. Stud.) </li></ul>"
					+ "</html>");
			credits.setAlignmentX(Component.CENTER_ALIGNMENT);
			credits.setHorizontalTextPosition(SwingConstants.CENTER);
			south.add(credits);
			label5.setIcon(new ImageIcon(Monitor.class
					.getResource("images/logo.png")));
			// label5.setPreferredSize(new Dimension(50, 50));
			label5.setAlignmentX(Component.CENTER_ALIGNMENT);
			south.add(label5);
			label5.setToolTipText("Visit the Unicam web site...");
		}
		south.setAlignmentX(Component.CENTER_ALIGNMENT);
		panel.add(south);
		getContentPane().add(panel);
		//
		pack();
		this.setLocationRelativeTo(null);
	}
}